﻿//作者：罗鑫
//时间：2009-4-22
//名称：角色管理grid

Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.RoleGrid = function (config) {
    Ext.apply(this, config);

    var AddUrl = this.url;
    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: AddUrl
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Name', 'Number', 'Description']
        }),
        remoteSort: true
    });

    this.store = fileStore;
    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        defaultNum: 21
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;
    fileStore.on('beforeload', function () {
        if (!fileStore.baseParams.data) {
            fileStore.baseParams = { data: '' };
        }
    });


    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();

    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    }, {
        header: '角色名称',
        dataIndex: 'Name',
        sortable: true
    }, {
        header: '编码',
        dataIndex: 'Number',
        sortable: true
    }, {
        header: '描述',
        dataIndex: 'Description',
        sortable: true,
        width: 200,
        renderer: function (value) {
            if (value != null) {
                return value;
            }
            else {
                return "暂没有相关描述";
            }
        }
    }
    ]

    FantastPlatform.UI.RoleGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
};
Ext.extend(FantastPlatform.UI.RoleGrid, Ext.grid.GridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.RoleGrid.superclass.onRender.call(this, ct, position);
    },
    //角色添加用户
    onAddUserClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行查看", "");
            } else {
                var fId = node[0].get('Id');
                var id = GUID();
                currtWind = openWind('Setting/PersonRoleForm.aspx?Id=' + fId, id, '添加角色用户', 700, 400, null);
            }
        }
    },


    //刷新按钮函数
    onUpdataRoleClick: function () {
        this.store.removeAll();
        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    }

  
});